package leetCode.cdj;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class Test {
//	private static final Map<Integer, Object> map = new HashMap<Integer, Object>();
	private static Map<Integer, Object> map = new ConcurrentHashMap<Integer, Object>();
	private Map<Integer, Object> map1 = new ConcurrentHashMap<Integer, Object>();

	public static void main(String[] args) {
		new Thread(new Runnable() {
			@Override
			public void run() {
				while(true) {
					int a = (int)(Math.random()*100000);
					try {
						map.put(a, a);
						new Test().map1.put(a, a);
					} catch (Exception e) {
						System.out.println("11111111"+e.getMessage());
					}
				}

			}
		}).start();
		new Thread(new Runnable() {
			@Override
			public void run() {
				while(true) {
					Iterator<Map.Entry<Integer, Object>> it = map.entrySet().iterator();
					try {
						while(it.hasNext()) {
							it.next().getValue();
						}
					} catch (Exception e) {
						System.out.println("2222"+e.toString());
					}
				}
				

			}
		}).start();
		new Thread(new Runnable() {
			@Override
			public void run() {
				while(true) {
					Iterator<Map.Entry<Integer, Object>> it1 = new Test().map1.entrySet().iterator();
					try {
						while(it1.hasNext()) {
							it1.next().getValue();
						}
					} catch (Exception e) {
						System.out.println("2222"+e.toString());
					}
				}
			}
		}).start();
	}

}
